﻿using System.Web;
using System.Web.Mvc;

namespace AMing.Mvc4.Core.Extension
{
    public static class ControllerExtension
    {
        /// <summary>
        /// 获取IP地址
        /// </summary>
        /// <param name="ctrl"></param>
        /// <returns></returns>
        public static string GetIP(this Controller ctrl)
        {
            string ip;
            if (ctrl.HttpContext.Request.ServerVariables["HTTP_VIA"] != null)
            {
                ip = ctrl.HttpContext.Request.ServerVariables["HTTP_X_FORWARDED_FOR"].ToString();
            }
            else
            {
                ip = ctrl.HttpContext.Request.ServerVariables["REMOTE_ADDR"].ToString();
            }
            return ip;

        }
        /// <summary>
        /// 客户端浏览器是否是IE6
        /// </summary>
        /// <param name="ctrl"></param>
        /// <returns></returns>
        public static bool IsIE6(this Controller ctrl)
        {
            HttpBrowserCapabilitiesBase bc = ctrl.Request.Browser;
            if (bc.IsBrowser("IE"))
            {
                if (bc.Version.Contains("6."))
                {
                    return true;
                }
            }
            return false;
        }

    }
}
